// 作业1:接受数字类型的参数，参数数量不定，完成累加和相乘

// function Operation(opt) {
//   this.arr = opt.arr;
//   this.add = function () {
//     const num = this.arr.reduce((allNum, elem) => {
//       return allNum + elem;
//     }, 0);
//     return num;
//   };

//   this.ride = function () {
//     const num = this.arr.reduce((allNum, elem) => {
//       return allNum * elem;
//     }, 1);
//     return num;
//   };
// }
// let operation1 = new Operation({ arr: [1, 2, 3, 4, 5] });

// console.log(operation1.add())
// console.log(operation1.ride())

// 作业2，构造车和人，人能选择车

function Vehicle(opt) {
  this.brand = opt.brand;
  this.color = opt.color;
  this.displacement = opt.displacement;
}

function Person(opt) {
  this.name = opt.name;
  this.age = opt.age;
  this.income = opt.income;
  this.choose = function (optVehicle) {
    const vehicle = new Vehicle(optVehicle);
    console.log(
      `${this.name}今年${this.age}岁，收入${this.income}元。买了${vehicle.color}颜色${vehicle.brand}牌子排量是${vehicle.displacement}的车子`
    );
  };
}
let personMa = new Person({
  name: "马少东",
  age: 27,
  income: 10000,
});
personMa.choose({ brand: "保时捷", color: "pink", displacement: 200 });
personMa.choose({ brand: "卡迪拉克", color: "green", displacement: 400 });
personMa.choose({ brand: "布加拉迪", color: "red", displacement: 1400 });
